package com.ldfile.server.config;


import lombok.Getter;
import lombok.Setter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Getter
public class UploadProgressListener {

    private HttpSession session;

    public UploadProgressListener(HttpServletRequest req) {
        session = req.getSession();
        session.setAttribute("status", new FileUploadStatus());
    }

    /* pBytesRead 到目前为止读取文件的比特数
     * pContentLength 文件总大小
     * pItems 目前正在读取第几个文件
     * 只要在session中实时保存文件上传的状态（这里我用fileUploadStatus类来封装）
     */
    public void update(long pBytesRead,long pContentLength) {
        FileUploadStatus status = (FileUploadStatus) session.getAttribute("status");
        status.setPBytesRead(pBytesRead+status.getPBytesRead());
        status.setPContentLength(pContentLength);
    }



    @Getter
    @Setter
    public static class FileUploadStatus {
        private Long pBytesRead=0L;
        private Long pContentLength=0L;
    }
}